//
//  KSCheckLogisticsDetailTableViewCell.swift
//  Supermarket
//
//  Created by Black_Crystal on 2017/9/27.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

class KSCheckLogisticsDetailTableViewCell: UITableViewCell {
    
    private let progressLineView = UIView()
    private let detailLabel = UILabel()
    private let timeLabel = UILabel()
    private let progressimg = UIImageView()
    private let progressView = UIView()
    private let lineView = UIView()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        
        progressimg.image = UIImage.init(named: "Home_Progress")
        progressimg.isHidden = true
        self.contentView.addSubview(progressimg)
        progressimg.snp.makeConstraints { (make) in
            make.top.equalTo(10)
            make.left.equalTo(20)
            make.width.height.equalTo(10)
        }
        
        progressView.backgroundColor = KSColor.kColor_line
        progressView.layer.cornerRadius = 3
        self.contentView.addSubview(progressView)
        progressView.snp.makeConstraints { (make) in
            make.top.equalTo(10)
            make.width.height.equalTo(6)
            make.centerX.equalTo(progressimg)
        }
        
        progressLineView.backgroundColor = KSColor.kColor_line
        self.contentView.addSubview(progressLineView)
        progressLineView.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(0)
            make.width.equalTo(1)
            make.centerX.equalTo(progressimg)
        }
        
        detailLabel.text = "汪汪汪汪汪无无无无汪汪汪汪汪无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无"
        detailLabel.font = UIFont.systemFont(ofSize: 15)
        detailLabel.numberOfLines = 0
        self.contentView.addSubview(detailLabel)
        detailLabel.snp.makeConstraints { (make) in
            make.top.equalTo(10)
            make.left.equalTo(progressLineView.snp.right).offset(20)
            make.right.equalTo(-10)
        }
        
        timeLabel.text = "2017-08-08 08:08:08"
        self.contentView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(detailLabel.snp.left)
            make.bottom.equalTo(self.contentView.snp.bottom).offset(-10)
        }
        
        lineView.backgroundColor = KSColor.kColor_line
        self.contentView.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.right.bottom.equalTo(0)
            make.left.equalTo(26)
            make.height.equalTo(1)
        }
    }
    
    func setDataWithConsultModel(consultModel: KSOrderRefundDetailDataLogsModel) {
        detailLabel.text = consultModel.info?.remark
    }
    
    func setDataWithLogisticModel(logisticModel: KSLogisticDetailDataDataModel) {
        detailLabel.text = logisticModel.context
    }
    
    
    func setProgressState(isLastRow: Bool,isFirst: Bool) {
        if isFirst {
            progressimg.isHidden = false
            progressView.isHidden = true
            progressLineView.snp.updateConstraints({ (make) in
                make.top.equalTo(20)
            })
        } else {
            progressimg.isHidden = true
        }
        
        if isLastRow {
            lineView.snp.updateConstraints({ (make) in
                make.left.equalTo(0)
            })
        }
    }
    
    func setCellHeight() -> CGFloat {
        detailLabel.sizeToFit()
        print(detailLabel.frame.origin.y + detailLabel.frame.height)
        return 200
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
